<template>
	<view class="parent">

		<view class="input-container">
			<view class="label"> 原密码 </view>
			<input class="et" placeholder="请输入原密码" v-model="form.password" password/>
		</view>

		<view class="input-container">
			<view class="label"> 新密码 </view>
			<input class="et" placeholder="请输入新密码" v-model="form.newpassword" password/>
		</view>
		
		<view class="input-container">
			<view class="label"> 再次密码 </view>
			<input class="et" placeholder="请输入再次密码" v-model="form.surepassword" password/>
		</view>
		
		<zy-button text="保存" @click.native="onRegister" style="margin-top: 100rpx"></zy-button>
	</view>
</template>

<script>
	import md5 from '@/main/common/md5.js';
	export default {
		data() {
			return {
				form: {
					password: '',
					newpassword: '',
					surepassword: '',
				}
			}
		},
		methods: {
			async onRegister(){
				if(!this.form.password){
					this.$common.showToast('请输入原密码')
					return
				}
				if(!this.form.newpassword){
					this.$common.showToast('请输入新密码')
					return
				}
				if(this.form.newpassword != this.form.surepassword){
					this.$common.showToast('两次密码不一致')
					return
				}
				let params = {
					password: md5.hex_md5(this.form.password),
					newpassword: md5.hex_md5(this.form.newpassword),
					surepassword: md5.hex_md5(this.form.surepassword),
				}
				
				let res = await this.$common.post('/app/user/xiugai', params);
				if(0 == res.code){
					this.$common.showToast('修改成功')
					setTimeout(()=>{
						uni.navigateBack();
					}, 500);
				}else{
					this.$common.showToast(res.msg)
				}
			},

		}
	}
</script>

<style lang="scss">
	.parent {
		background-color: #f5f5f5;
		height: 100vh;
		padding: 0 50rpx;
	}

	.input-container {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 90rpx;
		margin-top: 30rpx;
		background-color: #ededed;
		border-radius: 10rpx;
		
		.label {
			width: 150rpx;
			height: 100%;
			line-height: 90rpx;
			font-size: 36rpx;
			color: #222;
			text-align: center;
		}
		
		.et {
			height: 100%;
			line-height: 100rpx;
			padding: 0 20rpx;
			font-size: 28rpx;
			flex: 1;
		}
	}
	
</style>